//
//  PermissionsDetection.m
//  ClassManager
//
//  Created by mac on 2018/1/12.
//  Copyright © 2018年 GZX. All rights reserved.
//

#import "PermissionsDetection.h"
#import <Photos/Photos.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <CoreLocation/CoreLocation.h>

#define DeviceVersion [[[UIDevice currentDevice] systemVersion] floatValue]

@implementation PermissionsDetection

- (BOOL)isCanUsePhotos{
    if (DeviceVersion < 8.0) {
        ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus];
        if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied) {
            return NO;
        }
    }
    else {
        PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
        if (status == PHAuthorizationStatusRestricted ||
            status == PHAuthorizationStatusDenied) {
            return NO;
        }
    }
    return YES;
}

-(BOOL)isCanUseCamera{
    AVAuthorizationStatus authStatus =  [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
        return NO;
    }
    return YES;
}
-(BOOL)isCanUseMicrophone{
    AVAuthorizationStatus authStatus =  [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied){
        return NO;
    }
    return YES;
}
-(BOOL)isCanUseLocation{
    if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
        return NO;
    }
    return YES;

}



@end
